/*
 * Copyright 2006 Robert Burrell Donkin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package rat;

import java.io.File;
import java.io.PrintStream;

import rat.license.ILicenseMatcher;
import rat.license.standard.ApacheSoftwareLicense20;
import rat.license.standard.GeneratedLicenseNotRequired;
import rat.license.standard.JavaDocLicenseNotRequired;
import rat.license.standard.OASISLicense;
import rat.license.standard.W3CLicense;
import rat.license.util.MatcherMultiplexer;

public class Report {

	public static final void main(String args[]) throws Exception {
		if (args == null || args.length != 1) {
			printUsage();
		} else {
			Report report = new Report(args[0]);
			report.report(System.out);
		} 		
	}
	
	private static final void printUsage() {
		System.out.println("Usage: <directory>");
		System.out.println("       where <directory> is the base directory to be audited.");
		System.out.println("NOTE: RAT is really little more than a grep ATM");
		System.out.println("      RAT is also rather memory hungry ATM");
		System.out.println("      RAT is very basic ATM");
	}
	
	private final String baseDirectory;
	
	private Report(String baseDirectory) {
		this.baseDirectory = baseDirectory;
	}
	
	public void report(PrintStream out) {
		PrintStreamPrinter printer = new PrintStreamPrinter(out);
		File base = new File(baseDirectory);
        ILicenseMatcher[] matchers = {new ApacheSoftwareLicense20(), new W3CLicense(), 
                new OASISLicense(), new JavaDocLicenseNotRequired(), 
                new GeneratedLicenseNotRequired()};
		Directory directory = new Directory(base, new MatcherMultiplexer(matchers));
		LicenseChecker checker = new LicenseChecker(directory);
		checker.report(printer);
	}
}
